<?php
/***********************************************************************
 * @package    	IvanEngine
 * @subpackage 	Core
 * @author     	Ivan <ivanzx@msn.com>
 * @created    	2010-05-17
 ***********************************************************************/
if(defined("IVANENGINE_CORE_VALIDATOR_REGEX"))
	die("Redefinition macro in :".__FILE__."(".__LINE__.")");
define("IVANENGINE_CORE_VALIDATOR_REGEX", true);

require_once (dirname(__FILE__).'/ValidatorString.php');

class CValidatorRegex extends CValidatorString 
{
	const NR_Pattern	= 'NR_Pattern';
	
	protected function Initialize($options = array(), $messages = array())
  	{
  		parent::Initialize($options, $messages);

    	$this->AddRequiredOption(self::NR_Pattern);
  	}
  	
	protected function DoVerify($value) 
	{
	    $valid = parent::DoVerify($value);

    	if (!preg_match($this->GetOption(self::NR_Pattern), $valid))
    	{
      		throw new CExceptionValidator($this, self::NM_Invalid, array('value' => $value));
    	}

    	return $valid;
	}
}

?>